import 'package:baselib/utils/image_util.dart';
import 'package:baselib/widgets/comm_app_bar.dart';
import 'package:baselib/widgets/comm_textfield.dart';
import 'package:baselib/widgets/gradient_text_widget.dart';
import 'package:baselib/widgets/inkwell_button.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:framelib/utils/color_util.dart';
import 'package:framelib/utils/drawable_util.dart';
import 'package:framelib/utils/px_util.dart';
import 'package:framelib/utils/string_util.dart';
import 'package:framelib/widgets/comm_widget_manager.dart';
import 'package:framelib/widgets/main_gradient_button.dart';
import 'package:framelib/widgets/page_widget.dart';
import 'package:get/get.dart';
import 'package:module_business/module_index/viewmodel/room_set_view_model.dart';
/**
 * 房间设置主页
 */
class RoomSetPage extends GetWidget<RoomSetViewModel> {
  @override
  Widget build(BuildContext context) {
    return PageWidget.build(
        builder: (RoomSetViewModel model){
          return PageWidget.PageScaffoldWidget(
            isShowBg: true,
            appBar: CommAppBar(
              backgroundColor: ColorUtil.instance.color_transparent,
              titleStr: StringUtil.instance.Set,
              titleTextStyle: TextStyle(
                fontSize: PxUtil.instance.px_18,
                color: ColorUtil.instance.color_white,
                fontWeight: FontWeight.bold
              ),
              actions: [
                (!model.isHasPermission())?SizedBox(width: PxUtil.instance.px_0,):
                InkWellButton(
                  onPressed: ()=>model.save(),
                  child: Container(
                    padding: EdgeInsets.only(
                      left: PxUtil.instance.px_15,
                      right: PxUtil.instance.px_15,
                    ),
                    child: ImagesUtil.loadAssetImage(
                        DrawableUtil.instance.icon_room_set_save,
                        width: PxUtil.instance.px_36,
                        fit: BoxFit.fitWidth
                    ),
                  ),
                )
              ],
            ),
            body: Container(
              width: PxUtil.instance.screenWidth,
              height: PxUtil.instance.screenHeight-PxUtil.instance.statusBarHeight
                  -PxUtil.instance.appBarHeight,
              padding: EdgeInsets.only(
                left: PxUtil.instance.px_15,
                right: PxUtil.instance.px_15,
              ),
              child: ListView(
                children: [
                  //cover
                  InkWellButton(
                    onPressed: (!model.isHasPermission())?((){}):()=>model.onCoverTap(),
                    child: _buidlConverUi(model),
                  ),
                  //room name
                  _buildNameContInputUi(model,StringUtil.instance.Name,model.nameTextController,(!model.isHasPermission()),),
                  //Introduction
                  _buildNameContInputUi(model,StringUtil.instance.Introduction,model.introductionTextController,(!model.isHasPermission())),
                  //Password
                  _buildNameContInputUi(model,StringUtil.instance.Password,model.passwordTextController,(!model.isHasPermission())),
                  //Enable charm value
                  _buildEnableCharmUi(model),
                  //Release notification
                  InkWellButton(
                    onPressed: ()=>model.toFuncPage(StringUtil.instance.Release_notification),
                    child: _buildTitleClickItemUi(model: model,title: StringUtil.instance.Release_notification,)
                  ),
                  //Admins
                  InkWellButton(
                    onPressed: ()=>model.toFuncPage(StringUtil.instance.Admins),
                      child: _buildTitleClickItemUi(model: model,title: StringUtil.instance.Admins),
                  ),
                  //Blocklist
                  InkWellButton(
                    onPressed: ()=>model.toFuncPage(StringUtil.instance.Blocklist),
                    child: _buildTitleClickItemUi(model: model,title: StringUtil.instance.Blocklist),
                  ),
                  //Forbidden List
                  InkWellButton(
                    onPressed: ()=>model.toFuncPage(StringUtil.instance.Forbidden_List),
                    child: _buildTitleClickItemUi(model: model,title: StringUtil.instance.Forbidden_List),
                  ),
                ],
              ),
            ),
          );
        }
    );
  }

  _buidlConverUi(RoomSetViewModel model) {

    return Container(
      decoration: BoxDecoration(
          border: Border(
              bottom: BorderSide(
                  color: ColorUtil.instance.color_879d9d9d
              )
          )
      ),
      padding: EdgeInsets.only(
        top: PxUtil.instance.px_12,
        bottom: PxUtil.instance.px_12,
      ),
      child: Row(
        children: [
          CommWidgetManager.buildCicleImagWidget(
            model.roomInfo?.coverImg ?? '',
            placeholder: DrawableUtil.instance.icon_default_head,
            width: PxUtil.instance.px_70,
            height: PxUtil.instance.px_70,
            roundRadius: PxUtil.instance.px_35,
            backgroundColor: ColorUtil.instance.color_f2f2f2,
            padding: EdgeInsets.only(),
            margin: EdgeInsets.only(),
          ),
          Expanded(child: Container(
            margin: EdgeInsets.only(
                left: PxUtil.instance.px_20
            ),
            child: Text(
              StringUtil.instance.Room_cover_settings,
              style: TextStyle(
                  color: ColorUtil.instance.color_white,
                  fontWeight: FontWeight.w500,
                  fontSize: PxUtil.instance.px_16),
            ),
          )),
          (!model.isHasPermission())?SizedBox(width: PxUtil.instance.px_0,):
          ImagesUtil.loadAssetImage(
              DrawableUtil.instance.icon_arrow_right_white,
              width: PxUtil.instance.px_9,
              fit: BoxFit.fitWidth
          )
        ],
      ),
    );
  }

  _buildNameContInputUi(RoomSetViewModel model,String title,
      TextEditingController textController,bool readOnly){
    return Container(
      decoration: BoxDecoration(
          border: Border(
              bottom: BorderSide(
                  color: ColorUtil.instance.color_879d9d9d
              )
          )
      ),
      padding: EdgeInsets.only(
        top: PxUtil.instance.px_8,
        bottom: PxUtil.instance.px_8,
      ),
      child: Row(
        children: [
          Container(
            child: Text(
              '${title}：',
              style: TextStyle(
                color: ColorUtil.instance.color_white,
                fontSize: PxUtil.instance.px_16,
                fontWeight: FontWeight.w500,
              ),
            ),
          ),
          Expanded(
              child: TextField(
                controller: textController,
                readOnly: readOnly??false,
                style: TextStyle(
                    color: ColorUtil.instance.color_white
                ),
                decoration: const InputDecoration(
                    contentPadding: EdgeInsets.only(),
                    focusedBorder: UnderlineInputBorder(
                        borderSide: BorderSide(
                            width: 0, color: Colors.transparent)),
                    enabledBorder: UnderlineInputBorder(
                        borderSide: BorderSide(
                            width: 0, color: Colors.transparent))),
              ))
        ],
      ),
    );
  }

  _buildEnableCharmUi(RoomSetViewModel model) {
    return Container(
      decoration: BoxDecoration(
          border: Border(
              bottom: BorderSide(
                  color: ColorUtil.instance.color_879d9d9d
              )
          )
      ),
      padding: EdgeInsets.only(
        top: PxUtil.instance.px_20,
        bottom: PxUtil.instance.px_20,
      ),
      child: Row(
        children: [
          Expanded(
            child: Text(
              '${StringUtil.instance.Enable_charm_value}：',
              style: TextStyle(
                color: ColorUtil.instance.color_white,
                fontSize: PxUtil.instance.px_16,
                fontWeight: FontWeight.w500,
              ),
            ),
          ),
          Obx(() => ConstrainedBox(
            constraints: BoxConstraints(
                maxWidth: PxUtil.instance.px_40,
                maxHeight: PxUtil.instance.px_16),
            child: Transform.scale(
              scale: 0.8,
              child: CupertinoSwitch(
                value: model.isEnableCharmValue.value,
                onChanged: (isEnable) => model.setEnableCharmValue(isEnable),
                activeColor: ColorUtil.instance.color_964BF7,
                trackColor: ColorUtil.instance.color_A6ADC2,
                thumbColor: ColorUtil.instance.color_white,
              ),
            ),
          )),
        ],
      ),
    );
  }
  _buildTitleClickItemUi({
    RoomSetViewModel model,String title}) {
    return Container(
      decoration: BoxDecoration(
          border: Border(
              bottom: BorderSide(
                  color: ColorUtil.instance.color_879d9d9d
              )
          )
      ),
      padding: EdgeInsets.only(
        top: PxUtil.instance.px_24,
        bottom: PxUtil.instance.px_24,
      ),
      child: Row(
        children: [
          Expanded(
            child: Text(
              '${title}',
              style: TextStyle(
                color: ColorUtil.instance.color_white,
                fontSize: PxUtil.instance.px_16,
                fontWeight: FontWeight.w500,
              ),
            ),
          ),
          ImagesUtil.loadAssetImage(
              DrawableUtil.instance.icon_arrow_right_white,
              width: PxUtil.instance.px_9,
              fit: BoxFit.fitWidth
          )
        ],
      ),
    );
  }
}
